package com.mida.app.report.controller;

import com.mida.app.report.service.DocStructTemplateService;
import com.mida.app.report.service.MdmService;
import com.mida.app.report.vo.HospitolAndExamTypeVo;
import com.mida.app.report.vo.TemplateImageAndOrgUrlVo;
import com.mida.bms.report.api.DocStructTemplateApi;
import com.mida.bms.report.vo.DocReportPreservationRequest;
import com.mida.bms.report.vo.DocStructRequestVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：wang xiao le
 * @description：TODO 结构化模板报告
 * @date ：2021/4/6 11:45
 */
@RestController
@RequestMapping("/docStructTemplate")
@CrossOrigin
@Slf4j
public class DocStructTemplateController {
    @Autowired
    private DocStructTemplateApi docStructTemplateApi;

    @Autowired
    private DocStructTemplateService docStructTemplateService;

    @Autowired
    private MdmService mdmService;
    /**
     * 1、保存结构化模板
     *
     * @param docStructRequestVo 结构化模板vo
     * @return
     */
    @PostMapping(value = "add",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ActionResult add(@RequestBody DocStructRequestVo docStructRequestVo) throws Exception {
        return docStructTemplateApi.add(docStructRequestVo);
    }


    /**
     * 2.获取结构化模板回显json
     *
     * @param stTemplateInfoSoid 结构化模板基本信息soid
     * @return
     */
    @GetMapping("/getTemplate")
    @ResponseBody
    public ListResult<DocStructRequestVo> getTemplate(@RequestParam("stTemplateInfoSoid") Long stTemplateInfoSoid) {
        return docStructTemplateApi.getTemplate(stTemplateInfoSoid);
    }


    /**
     * 4 获取报告模板缩略图
     *
     * @param stTemplateInfoSoid
     * @return
     */
    @GetMapping("/getTemplatePic")
    @ResponseBody
    public ListResult<DocStructRequestVo> getTemplatePic(@RequestParam("stTemplateInfoSoid") Long stTemplateInfoSoid) {
        return docStructTemplateApi.getTemplatePic(stTemplateInfoSoid);
    }

    /**
     * 5.业务态保存报告模板
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/saveTemplate",consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ActionResult saveTemplate(@RequestBody DocReportPreservationRequest request) {
        return docStructTemplateApi.saveTemplate(request);
    }


    /**
     * 6.获取医院logo和模板底图
     *
     * @param orgInfoSoid  组织soid
     */
    @GetMapping(value = "/queryTemplateImageAndOrgUrl", produces = {"application/json;charset=UTF-8"})
    public ListResult<TemplateImageAndOrgUrlVo> queryTemplateImageAndOrgUrl(@RequestParam("orgInfoSoid") Long orgInfoSoid){
        ListResult<TemplateImageAndOrgUrlVo> listResult = new ListResult<>();
        try {
            return docStructTemplateService.queryTemplateImageAndOrgUrl(orgInfoSoid);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            listResult.setMessage("获取医院logo和模板底图失败");
            listResult.setStatus(HttpStatus.BAD_REQUEST.value());
            return listResult;
        }
    }

    /**
     * 7 根据人的信息查询医院和检查类型
     *
     * @param
     * @return
     */
    @GetMapping("/queryHospitolAndExamType")
    @ResponseBody
    public ListResult<HospitolAndExamTypeVo> queryHospitolAndExamType() {
        return mdmService.queryHospitolAndExamType();
    }
}
